package com.leetcode.LC;

public class LC24 {
    public ListNode swapPairs(ListNode head) {
        ListNode listNode = new ListNode(0);
        ListNode a = listNode, b = head;
        a.next = head;
        while (a.next != null && a.next.next != null) {
            ListNode n1 = a.next;
            ListNode n2 = a.next.next;
            a.next=n2;
            n1.next=n2.next;
            n2.next=n1;
            a=n1;
        }
        return listNode.next;
    }
}
/**
 * Definition for singly-linked list.
 * public class ListNode {
 * int val;
 * ListNode next;
 * ListNode() {}
 * ListNode(int val) { this.val = val; }
 * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */